package com.ys.controller.web.finance;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.ys.service.finance.TcwWanliPrepaymentRecordedService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import com.ys.config.MenuId;
import com.ys.dto.SubGridConfigDto;
import com.ys.entity.finance.TcwWanliPrepaymentRecorded;
import com.ys.entity.finance.TcwWanliPrepaymentRecordedItem;
import com.ys.service.sys.CommonApiService;
import com.ys.vo.W;

/**
 * 万里汇预付款入账单
 */
@Controller
@RequestMapping("/web/finance/tcwWanliPrepaymentRecorded")
public class WebTcwWanliPrepaymentRecordedController {
	private static final Logger logger = LoggerFactory.getLogger(WebTcwWanliPrepaymentRecordedController.class);

	@Autowired
	private CommonApiService<TcwWanliPrepaymentRecorded> commonApiService;


    @Autowired
    private TcwWanliPrepaymentRecordedService tcwWanliPrepaymentRecordedService;

    /*
     * 新增
     */
    @GetMapping("/toAdd")
    public String toAdd(Model model, HttpServletRequest request, HttpServletResponse response) {
        try {
            Map<String, Object> extraParam = new HashMap<>();
            //关联数据
            extraParam.put("status", 1);



            TcwWanliPrepaymentRecorded entity = new TcwWanliPrepaymentRecorded();
            //关联数据
            String bid = commonApiService.getCommonNextBid(MenuId.TCW_WanliPrepaymentRecorded);
            entity.setBid(bid);

            // 子列表配置信息
            SubGridConfigDto subGridConfig = commonApiService.getSubGrid(MenuId.TCW_WanliPrepaymentRecorded,new ArrayList<>());
            commonApiService.toAdd(model, entity, MenuId.TCW_WanliPrepaymentRecorded, extraParam, subGridConfig);

            return "finance/tcwWanliPrepaymentRecorded/toAdd";
        }catch (Exception e) {
            logger.error("新增页面出错：",e.getMessage(),e);
            return W.error(model, e.getMessage());
        }
    }

    /*
     * 编辑
     */
    @GetMapping("/toEdit")
    public String toEdit(Model model, HttpServletRequest request, HttpServletResponse response, String bid) {
        try {
            Map<String, Object> extraParam = tcwWanliPrepaymentRecordedService.getExtraParam(bid);

            List<Map<String, Object>> itemList = tcwWanliPrepaymentRecordedService.getItemList(bid);
            // 子列表配置信息
            SubGridConfigDto subGridConfig = commonApiService.getSubGrid(MenuId.TCW_WanliPrepaymentRecorded,itemList);

            commonApiService.toEdit(model,Long.parseLong(extraParam.get("id").toString()), new TcwWanliPrepaymentRecorded(), MenuId.TCW_WanliPrepaymentRecorded, extraParam, subGridConfig);

        	return "finance/tcwWanliPrepaymentRecorded/toEdit";
        }catch (Exception e) {
            logger.error("编辑页面出错：",e.getMessage(),e);
            return W.error(model, e.getMessage());
        }
    }



}






